package com.wondersgroup.easyexceldome.controller;

import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
import com.wondersgroup.easyexceldome.model.TestDto;
import com.wondersgroup.easyexceldome.util.ExcelUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author: lizhu@wondesgroup.com
 * @date: 2020/4/27 14:37
 * @description:
 */
@RestController
public class TestController {
    @RequestMapping("/exportTest")
    public void exportEnterpriseBillV2(HttpServletResponse response) throws Exception {
        //模模拟sql查出的数据
        TestDto testDto = new TestDto();
        testDto.setDate(new Date());
        testDto.setDoubleData(2.232);
        testDto.setIgnore("哈哈哈");
        testDto.setString("easyExcel测试1");
        TestDto testDto2 = new TestDto();
        testDto2.setDate(new Date());
        testDto2.setDoubleData(1.111);
        testDto2.setIgnore("啦啦啦");
        testDto2.setString("easyExcel测试2");
        List<TestDto> list = new ArrayList<>();
        list.add(testDto);
        list.add(testDto2);
        ExcelUtil.writeExcel(response,list,"导出测试","sheet单1");
    }
    @RequestMapping("/exportTest3")
    public void exportEnterpriseBillV3(HttpServletResponse response) throws Exception {
        //模模拟sql查出的数据
        List<TestDto> dtos=new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            dtos.add(TestDto.builder().string(i+"").date(new Date()).doubleData(i+0.1).doubleData2(i+0.2).ignore(i+"").build());
        }
        OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy=new OnceAbsoluteMergeStrategy(3, 5, 0, 0);
        ExcelUtil.writeExcelMergeStrategy(response,dtos,"导出测试","sheet单1",onceAbsoluteMergeStrategy);
    }


}
